<extend name="common:base" />
<block name="content">
    <div id="header">
        <div class="header">
            <h1 class="tit">{$site_title}</h1>
        </div>
    </div>
    <p class="binding">已绑定手机号<if condition="$open_code eq 1">（此号收验证码）</if></p>
    <p class="binding-tel">{:session('amobile')}</p>
    <div class="edit_mobile">
        <form action="{:U('Setting/edit_mobile')}" method="post">
            <input class="ipt-tel" type="number" placeholder="请输入新手机号" name="mobile" required maxlength="11"/>
            <if condition="$open_code eq 1">
                <div class="ipt-code">
                    <input class="entry-conde" type="text" placeholder="请输入验证码" name="incode" required/>
                    <span class="send-code" id="sendSms">点击获取</span>
                </div>
                <else/>
                <div class="ipt-code">
                    <input class="ipt-tel" type="password" placeholder="请输入登陆密码" name="pwd" required/>
                </div>
            </if>
            <button class="confirm" type="submit">确认</button>
        </form>
    </div>
</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/binding_tel.css" />
</block>
<block name="JS">
    <script type="text/javascript">
        $(function(){
            //点击发送短信
            var clock = "";
            $('#sendSms').click(function () {
                var ff = $(this).attr("for");
                if(ff == 1){
                    return false;
                }
                var phone = "{:session('amobile')}";
                if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))) {
                    layer.msg('手机号码格式不正确！', {time:1500});
                } else {
                    $.ajax({
                        type: 'post',
                        url: "{:U('User/sms')}",
                        data: { phone: phone},
                        success: function (msg) {
                            if(msg.status == 1){
                                layer.msg('短信发送成功', {time:1000});
                                clock = setInterval(GetRunTime ,1000);
                            }else{
                                layer.msg(msg.msg , {time:1500});
                            }
                        }
                    });
                }
            });

            var second = 60;
            function GetRunTime()
            {
                if(second > 0){
                    second -= 1;
                    $("#sendSms").text(second + "S");
                    $("#sendSms").attr("for" ,"1");
                    $("#sendSms").css("background" ,"#ccc");
                }else{
                    second = 60;
                    clearInterval(clock);
                    $("#sendSms").text("重新获取");
                    $("#sendSms").attr("for" ,"0");
                    $("#sendSms").css("background" ,"#61cf9f");
                }
            }
        });
    </script>
</block>